package com.example.sensor.slice;

import com.example.sensor.*;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private Button mBtnAccelerometer;
    private Button mBtnCompass;
    private Button mBtnLocator;
    private Button mBtnGeoconvert;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        mBtnAccelerometer = (Button) findComponentById(ResourceTable.Id_btn_accelerometer);
        mBtnAccelerometer.setClickedListener(this);
        mBtnCompass = (Button) findComponentById(ResourceTable.Id_btn_compass);
        mBtnCompass.setClickedListener(this);
        mBtnLocator = (Button) findComponentById(ResourceTable.Id_btn_locator);
        mBtnLocator.setClickedListener(this);
        mBtnGeoconvert = (Button) findComponentById(ResourceTable.Id_btn_geoconvert);
        mBtnGeoconvert.setClickedListener(this);


    }

    @Override
    public void onClick(Component component) {
        if (component.getId() == ResourceTable.Id_btn_accelerometer) {
            // 启动AccelerometerAbility
            startAbility(Utils.generatePageNavigationIntent(AccelerometerAbility.class.getName()));
        }
        if (component.getId() == ResourceTable.Id_btn_compass) {
            // 启动CompassAbility
            startAbility(Utils.generatePageNavigationIntent(CompassAbility.class.getName()));
        }
        if (component.getId() == ResourceTable.Id_btn_locator) {
            // 启动LocatorAbility
            startAbility(Utils.generatePageNavigationIntent(LocatorAbility.class.getName()));
        }
        if (component.getId() == ResourceTable.Id_btn_geoconvert) {
            // 启动GeoConvertAbility
            startAbility(Utils.generatePageNavigationIntent(GeoConvertAbility.class.getName()));
        }
    }
}
